#include "GameEventManager.h"

GameEventManager g_pEventManager;

void GameEventManager::Init()
{
	char    IniPath[512];
	wchar_t szPath[512];
	SD_Tools::GetRealDir(g_pInterfaces.hModuleBase, szPath, 512);
	
	wcstombs(IniPath, szPath, 512);

	JUNK_CODE;
	sprintf(szWav, /*%s\\Hitmarker.wav*/XorStr(16, 0xCB, 0xEE399500, 0xAE32A825, 0xB129A432, 0x9149DC4A).c_str(), IniPath); 
	
	bRoundsay = true;
}

void GameEventManager::FireGameEvent(IGameEvent *event)
{
	const char* szEventName = event->GetName();
	if( !szEventName )
		return;

	if(!lstrcmpA(szEventName, /*player_hurt*/XorStr(11, 0xBC, 0xCC57DB40, 0xDD45E95D, 0xC141C600).c_str()))
	{
		int me = g_pInterfaces.g_pEngine->GetLocalPlayer();
		int dead = g_pInterfaces.g_pEngine->GetPlayerForUserID(event->GetInt(/*userid*/XorStr(6, 0xE6, 0x93168111, 0x8B050000).c_str()));
		JUNK_CODE;
		int killer = g_pInterfaces.g_pEngine->GetPlayerForUserID(event->GetInt(/*attacker*/XorStr(8, 0xC9, 0xA83CB327, 0xA62FA630).c_str()));
		JUNK_CODE;
		if(killer == me && dead != me)
		{
			hitplayer = true;
			PlaySoundA(szWav, NULL, SND_FILENAME|SND_ASYNC|SND_NOSTOP);
		}
	}
}

void GameEventManager::RegisterSelf()
{
	g_pInterfaces.g_pGameEventManager->AddListener( this, /*round_start*/XorStr(11, 0xAA, 0xD846DD49, 0xC27AD757, 0xC353D400).c_str(), false );
	JUNK_CODE;
	g_pInterfaces.g_pGameEventManager->AddListener( this, /*player_hurt*/XorStr(11, 0xBC, 0xCC57DB40, 0xDD45E95D, 0xC141C600).c_str(), false );
}